package net.towee.model.bittorrent.impl;

import java.util.Date;

import net.towee.model.bittorrent.Peer;

import com.google.code.morphia.annotations.Embedded;

/**
 * Implementation of peer
 * @author c58
 */
@Embedded
public class PeerImpl implements Peer {
	private String id;
	private String ip;
	private String accountId;
	private int port;
	private boolean seeder;
	private Date lastRequest;
	
	public PeerImpl() {}
	public PeerImpl(String accountId, String id, String ip, int port) {
		this.id = id;
		this.ip = ip;
		this.port = port;
		this.lastRequest = new Date();
		this.seeder = false;
	}
	
	@Override
	public String getId() {
		return id;
	}

	@Override
	public String getIp() {
		return ip;
	}

	@Override
	public int getPort() {
		return port;
	}

	@Override
	public boolean isSeeder() {
		return seeder;
	}

	@Override
	public void setSeeder() {
		seeder = true;
	}

	@Override
	public Date getLastRequestDate() {
		return lastRequest;
	}

	@Override
	public void setLastRequestDate() {
		this.lastRequest = new Date();
	}
	@Override
	public String getAccountId() {
		return accountId;
	}

	@Override
	public boolean equals(Object o) {
		if(o == this)
			return true;
		if(o instanceof Peer && ((Peer)o).getId().equals(getId()))
			return true;
			
		return false;
	}
}
